package robot;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.logging.Logger;

import com.google.wave.api.Blip;

public class StatusController
{
	private static final Logger log = Logger.getLogger(StatusController.class.getName());
	
	private Hashtable<String, Hashtable<String, String>> waveMap = new Hashtable<String, Hashtable<String, String>>();

	
	public void updateStatus(String waveId, String name,String status)
	{
		Hashtable<String, String> statusMap = waveMap.get(waveId);
		if (statusMap == null)
		{
			statusMap = new Hashtable<String, String>();
			waveMap.put(waveId, statusMap);
		}
		statusMap.put(name, status);
		 log.info("status update complete");
	}
	
	 public void renderStatusList(Blip blip, String waveId)
	 {
		 Hashtable<String, String> statusMap = waveMap.get(blip.getWavelet().getWaveId());
		 if (statusMap != null)
		 {
			 blip.getDocument().delete();
			 //Append full status list at the end of the wave
			 for (Enumeration<String> nameKyes = statusMap.keys(); nameKyes.hasMoreElements();)
			 {
				 String name = nameKyes.nextElement();
				 String status = statusMap.get(name);
				 blip.getDocument().append("\n" + name + " : " + status);
			 }
			 blip.getDocument().append("\n");
		 }
			
	 }
	 

}
